layui.use(['form','layer'],function(){
    var form = layui.form
    layer = parent.layer === undefined ? layui.layer : top.layer,

    $ = layui.jquery;

    //校验字段是否为空
    form.verify({
        title : function(val){
            if(val == ''){
                return "菜单名称不能为空";
            }
        },
        clazz : function(val){
            if(val == ''){
                return "请选择菜单层级";
            }
        } ,
        href : function(val){
            if(val == ''){
                return "菜单路径不能为空";
            }
        }
    })
    //提交数据
    form.on("submit(addMenu)",function(data){
        //弹出loading
        var msg = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        var index=layer.index;
        var id =$(".id").val();
        var title =$(".title").val();
        var clazz =$("#clazz").val();
        var code =$(".code").val();
        var pcode =$(".pcode").val();
        var href =$(".href").val();
        var icon =$(".icon").val();
        var ismenu =$("#ismenu").val();
        var params ={"id":id,"title":title,"clazz":clazz,"code":code,"pcode":pcode,"href":href,"icon":icon,"ismenu":ismenu};
        console.log(params);
       $.post(Feng.ctxPath+"/sysMenu/addMenu",params,function(data){
            if(data.success){
                setTimeout(function(){
                    top.layer.close(msg);
                    top.layer.msg(data.message);
                    top.layer.close(index);
                    //刷新父页面
                    window.parent.location.reload();
                },500);
            }else{
                top.layer.close(msg);
                top.layer.msg(data.message);
            }
        },"json");

        /*setTimeout(function(){
            top.layer.close(index);
            top.layer.msg("文章添加成功！");
            layer.closeAll("iframe");
            //刷新父页面
            parent.location.reload();
        },500);*/
        return false;
    })
    //取消
    $(".cancel").click(function(){
        close_self();
        layer.close(layer.index);
    })
    function close_self() {
        var index=parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }

})